package com.java.lesson.c;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class map_get {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();

        map.put("STU001","Andy");
        map.put("STU002","Jack");
        map.put("STU003","Tom");
        map.put("STU004","Bob");

        //get通过键获取值
        System.out.println(map.get("STU003"));
        System.out.println("------------------");
        //keySet 获取所有键的Set集合
        Set<String> keySet = map.keySet();
        System.out.println(keySet);
        //values  获取所有值的Collection集合
        Collection<String> values = map.values();
        System.out.println(values);
        //entrySet  获取所有键值对对象的Set集合
        Set<Map.Entry<String, String>> es = map.entrySet();
        //Map集合通过entrySet()方法转换成的这个Set集合，Set集合中元素的类型是 Map.Entry<K,V>
        //Map.Entry和String一样，都是一种类型的名字，只不过：Map.Entry是静态内部类，是Map中的静态内部类
        System.out.println(es);
        //[STU001=Andy, STU003=Tom, STU002=Jack, STU004=Bob]
        for (Map.Entry<String, String> entry:es){
            System.out.println("key:"+entry.getKey()+"    "+"value:"+entry.getValue());
        }
        /*
        key:STU001    value:Andy
        key:STU003    value:Tom
        key:STU002    value:Jack
        key:STU004    value:Bob
         */
    }

}
